package com.pulaien.shop.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.pulaien.system.domain.Label;
import com.pulaien.system.domain.dto.BlogDto;
import com.pulaien.system.service.ILabelService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.pulaien.common.annotation.Log;
import com.pulaien.common.core.controller.BaseController;
import com.pulaien.common.core.domain.AjaxResult;
import com.pulaien.common.enums.BusinessType;
import com.pulaien.system.domain.Blog;
import com.pulaien.system.service.IBlogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.pulaien.common.utils.poi.ExcelUtil;
import com.pulaien.common.core.page.TableDataInfo;

/**
 * 博客Controller
 * 
 * @author pulaien
 */
@RestController
@RequestMapping("/shop/blog")
@Api(tags = "BlogController", description = "博客")
public class ShopBlogController extends BaseController
{
    @Autowired
    private IBlogService blogService;

    @Autowired
    private ILabelService labelService;

    /**
     * 查询博客列表
     */
    @ApiOperation(value = "博客列表")
    @GetMapping("/list")
    public TableDataInfo list(String labelId)
    {
        return blogService.getListByLabelId(labelId);
    }

    /**
     * 查询博客列表
     */
    @ApiOperation(value = "标签列表")
    @GetMapping("/getLable")
    public TableDataInfo getLable()
    {
        List<Label> list = labelService.list(new LambdaQueryWrapper<Label>().eq(Label::getDelFlag,0).orderByDesc(Label::getSort));
        return getDataTable(list);
    }

    /**
     * 获取博客详情
     */
    @ApiOperation(value = "获取博客详情")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        BlogDto blogDto = blogService.getDetailsById(id);
        return AjaxResult.success(blogDto);
    }
}
